package com.yang.demo.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * 日期格式转换
 * @author xiaoyang
 * @since 1.0.0
 */

@Component
public class DateConverter implements Converter<String, LocalDate> {

    @Override
    public LocalDate convert(String source) {
        try {
            return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd").withLocale(Locale.CHINA));
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("日期时间解析异常");
        }
        return null;
    }
}

